package ynu.edu.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import ynu.edu.entity.Cart;
import java.util.List;

public interface CartRepository extends JpaRepository<Cart, Integer> {
    List<Cart> findByUserId(Integer userId);
    
    List<Cart> findByUserIdAndBusinessId(Integer userId, Integer businessId);
    
    @Modifying
    @Query("UPDATE Cart c SET c.quantity = :quantity WHERE c.userId = :userId AND c.businessId = :businessId AND c.foodId = :foodId")
    int updateQuantity(@Param("userId") Integer userId, 
                      @Param("businessId") Integer businessId, 
                      @Param("foodId") Integer foodId, 
                      @Param("quantity") Integer quantity);
    
    int deleteByUserIdAndBusinessIdAndFoodId(Integer userId, Integer businessId, Integer foodId);
    
    int deleteByUserIdAndBusinessId(Integer userId, Integer businessId);
} 